import java.io.*;
import java.net.*;
import java.util.*;
import java.security.Security;
import java.security.Provider;
import javax.net.ssl.*;
public class httpsConnecter {    

    private String userName              = null;
    private String passWord              = null;
    private String authUrl               = null;
    private StringBuffer connMessageBf   = new StringBuffer();
    private StringBuffer returnMessageBf = new StringBuffer();

    public static void main(String[] args) {

	if (args.length !=3) {
	    System.out.println("=============================");
	    System.out.println("[url] [user_name] [password]");
	    System.out.println("=============================");
	    System.exit(0);
	}

	httpsConnecter c = new httpsConnecter ();
	c.setUrl(args[0]);
	c.setUserName(args[1]);
	c.setPassWord(args[2]);
	c.connecting();
    }

    public void setUrl (String url) {
	authUrl = url;
    }

    public void setUserName (String user_name) {
	userName = user_name;
    }

    public void setPassWord (String pass_word) {
	passWord = pass_word;
    }

    public String getConnMessage () {
	return connMessageBf.toString();
    }

    public String getReturnMessage () {
	return returnMessageBf.toString();
    }

    public void connecting () {
        
	HttpsURLConnection httpsConnection = null;

	try {            

	    URL url = new URL (authUrl);
            
	    try {                
		httpsConnection = (HttpsURLConnection)url.openConnection();                
		//httpConnection.setDoOutput(true);                
		httpsConnection.setRequestProperty("Authorization", encodeAuthorization(userName, passWord));
		httpsConnection.setRequestProperty("MSIE", "msie 6");
		httpsConnection.connect(); 
		
                connMessageBf.append("ResponseCode="+httpsConnection.getResponseCode());
		
		connMessageBf.append("ResponseMessage="+httpsConnection.getResponseMessage());
                
		System.out.println(connMessageBf.toString());

		BufferedReader in = new BufferedReader(new InputStreamReader (httpsConnection.getInputStream()));

		String input = "";
		/*
		do {
		    input += in.readLine();
		    System.out.println(input);
		}while (in.readLine() != null);
		   
		*/
		input = in.readLine();
		while (input != null) {
		    returnMessageBf.append(input+"\n");
		    input = in.readLine();
		}
		System.out.println(input);
		
		//System.out.println(returnMessageBf.toString());
		in.close();            

	    } catch (IOException ioe) {                
		System.out.println("Error1="+ioe.getMessage()); 
		System.exit(1);         
	    }        
	} catch (MalformedURLException mue) {            
	    System.out.println("Error2="+mue.getMessage());            
	    System.exit(1);         
	} catch (Exception e) {
	    System.out.println("Error3="+e.getMessage());            
	    e.printStackTrace();            
	    System.exit(1);         
	}    
    }


    private static String encodeAuthorization (String username, String passwd) {

	String authorization = username + ":" + passwd;
	sun.misc.BASE64Encoder enCoder = new sun.misc.BASE64Encoder();
	return "Basic " + enCoder.encode(authorization.getBytes());
    }
}






